home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!ues5.cern.ch
- From: Dan Pop <Dan.Pop@cern.ch>
- Newsgroups: comp.lang.c
- Subject: Re: Function pointers in C -- HELP!
- Date: Mon, 12 Feb 1996 21:31:26 +0100
- Organization: CERN European Lab for Particle Physics
- Message-ID: <9602122031.AA07749@ues5.cern.ch>
- References: <311F8FE4.C99@dimensional.com>
- X-NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
- X-Mail2News-Path: mail1.cern.ch!ues5.cern.ch
-
- Eric Seale <seale@dimensional.com> writes:
-
- >Every compiler I've tried barfs on the indicated line in this
- >code. I can't see what I'm doing wrong -- can somebody lend me a
- >hand (the compilers seem to dislike the "(ID)")?
- >
- > #include <stdio.h>
- >
- > void ptr_test(void);
- > int test_entry_1(int);
- ^^^
- This declaration is in open conflict with the definition of test_entry_1.
-
- > void ptr_test() {
- > int *funct_ptr;
-
- Either I'm a complete idiot or funct_ptr is declared as a pointer to int.
-
- > int ID;
- >
- > funct_ptr = (int *)test_entry_1;
-
- The standard doesn't define the result of converting a pointer to function
- to pointer to int (or any other data type).
-
- > ID = 2;
- >
- >>> (*funct_ptr) (ID);
-
- This syntax requires funct_ptr to be pointer to function, which it isn't,
- hence the compiler diagnostic.
-
- > }
- >
- >
- > void test_entry_1(int ID) {
- ^^^^
- > printf("Test entry 1 called, with ID of %2d\n", ID);
- > }
-
- Open your C book and learn how to declare a pointer to function.
- This is a too basic topic to be discussed in the newsgroup.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-